package net.mlike.openssp.server.dto;

import org.springframework.http.HttpStatus;

/**
 * Created by wallellen@hotmail.com on 5/24/18.
 */
public class Message<T> {
    private int code;
    private T data;

    public static Message success() {
        Message message = new Message();
        message.code = HttpStatus.OK.value();
        return message;
    }

    public static <T> Message success(T data) {
        Message<T> message = new Message<>();
        message.code = HttpStatus.OK.value();
        message.data = data;

        return message;
    }

    public static Message failure() {
        Message message = new Message();
        message.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
        return message;
    }

    public static <T> Message failure(T data) {
        Message<T> message = new Message<>();
        message.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
        message.data = data;

        return message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
